package com.ryl.yomall.product.controller;


import com.ryl.yomall.model.common.result.Result;
import com.ryl.yomall.product.utils.FileUtil;
import org.csource.common.MyException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Author: ryl
 * @Time: 14:20
 * @Description:
 * 上传文件
 */
@RestController
@RequestMapping("admin/product")
public class FileController {

    @Value("${img.url}")
    private String imgUrl;
    //上传图片
    @PostMapping("fileUpload")
    //public Result fileUpload(@RequestParam MultipartFile[] file){批量上传
    public Result fileUpload(MultipartFile file){
        //原始名称
//        System.out.println(file.getOriginalFilename());
//
//        System.out.println(file.getSize());
//        System.out.println(file.getName());
        String conf="fdfs_client.conf.sample";
        String p = null;
        try {
            p = FileUtil.getUrl ( conf ,file );
        } catch (IOException e) {
            e.printStackTrace ( );
        } catch (MyException e) {
            e.printStackTrace ( );
        }
        //硬编码问题
        return Result.ok(imgUrl + p);
    }
}
